package com.school.util;



import java.io.InputStream;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;


import java.util.Properties;



public final class  WhetherNotToUpdate {
	
	private static boolean Pattern = false;//模式
	private static boolean switchgear = false;//开关机
	private static boolean VersionUpdate  = false;//版本跟新
	
	
	public static boolean isPattern() {
		return Pattern;
	}


	public static void setPattern(boolean pattern) {
		Pattern = pattern;
	}


	public static boolean isSwitchgear() {
		return switchgear;
	}


	public static void setSwitchgear(boolean switchgear) {
		WhetherNotToUpdate.switchgear = switchgear;
	}
	
	


	public static boolean isVersionUpdate() {
		return VersionUpdate;
	}


	public static void setVersionUpdate(boolean versionUpdate) {
		VersionUpdate = versionUpdate;
	}


	public static void allTrue() {
		WhetherNotToUpdate.Pattern = true;
		WhetherNotToUpdate.VersionUpdate = true;
		WhetherNotToUpdate.VersionUpdate = true;
		
	}
	
	
	public static boolean oneFalse() {
		if(WhetherNotToUpdate.Pattern || WhetherNotToUpdate.switchgear||WhetherNotToUpdate.VersionUpdate) {
			return true;
			
		}else {
			return false;
		}
		
	}
	
	public static void allFalse() {
		WhetherNotToUpdate.Pattern = false;
		WhetherNotToUpdate.switchgear = false;
		WhetherNotToUpdate.VersionUpdate = false;
	}
	
	static Map<String, Boolean>mapStateUpdateData = new HashMap<>();
	public static Map<String, Boolean> modifyOut(String mac){
			if(mapStateUpdateData.containsKey(mac)) {}else {
				mapStateUpdateData.put(mac+"Pattern", true);
				mapStateUpdateData.put(mac+"Switchgear", true);
				mapStateUpdateData.put(mac+"VersionUpdate", true);
		}
		return mapStateUpdateData;
	}
	
	public static void patternAllTrue(){
		WhetherNotToUpdate.modify("Pattern");
	}
	
	public static void switchgearAllTrue(){
		WhetherNotToUpdate.modify("Switchgear");
	}
	
	public static void VersionUpdateAllTrue(){
		WhetherNotToUpdate.modify("VersionUpdate");
	}
	
	public static void modify(String data){
		for(Entry<String, Boolean> temp : mapStateUpdateData.entrySet()) {
            System.out.println("K: "+temp.getKey()+",V: "+temp.getValue());
            if(temp.getKey().contains(data)) {
            	mapStateUpdateData.put(temp.getKey(), true);
            }
            System.out.println("K: "+temp.getKey()+",V: "+temp.getValue());
		}
	}
	
	
	
	
	public static String getWook() {
		Date date = new Date();  
        SimpleDateFormat dateFm = new SimpleDateFormat("EEEE");  
        String currSun = dateFm.format(date);  
		return currSun;

	}
	
	
	public static void main(String[] args) throws UnknownHostException {
	//	WhetherNotToUpdate.allTrue();
	//	System.out.println(getIp());
		/*try {
			ApkFile apk = new ApkFile("E:/work/tomcat/app-release.apk");
			System.out.println(apk.getApkMeta().getVersionCode());
		} catch (IOException e) {
			e.printStackTrace();
		}*/
		
		WhetherNotToUpdate.switchgearAllTrue();
	}
	
	
	public static String getIp() throws UnknownHostException {
	//InetAddress addr = InetAddress.getLocalHost();  
   // String ip=addr.getHostAddress().toString();
	//return "http://"+ip+":8080/";
	
	
	String value = "";
	try {
		Properties pro = new Properties();
		InputStream fis = WhetherNotToUpdate.class.getResourceAsStream("/ip.properties");
		pro.load(fis);
		value = "http://"+pro.getProperty("ip")+"/";
		fis.close();
		
	} catch (Exception e) {
		e.printStackTrace();
	}
	return value;
	}
	
	
	
	public static String getSaveDisk () throws UnknownHostException {
		//return "/school/img/";
		return "E:/work/tomcat/apache-tomcat-8.0.48/webapps/image/class/";
		}
	
	
	public static String getSaveDiskApk () throws UnknownHostException {
		//return "/school/";
		return "E:/work/tomcat/apache-tomcat-8.0.48/webapps/";
		}
	
	public static String getReadDisk() {
		return "/image/class/";
		//return "/img/";
		
	}
	
	/**
	 * 获取指定视频的帧并保存为图片至指定目录
	 * @param videofile  源视频文件路径
	 * @param framefile  截取帧的图片存放路径
	 * @throws Exception 
	 * @throws Exception
	 */
/*	public static Integer fetchFrame(String videofile, String framefile ,Integer frameNumber)
	        throws Exception {
	    File targetFile = new File(framefile);
	    FFmpegFrameGrabber ff = new FFmpegFrameGrabber(videofile); 
	    ff.start();
	    int lenght = ff.getLengthInFrames();
	    int i = 0;
	    Frame f = null;
	    while (i < lenght) {
	        // 过滤前5帧，避免出现全黑的图片，依自己情况而定
	        f = ff.grabFrame();
	        if ((i > frameNumber) && (f.image != null)) {
	            break;
	        }
	        i++;
	    }
	    IplImage img = f.image;
	    int owidth = img.width();
	    int oheight = img.height();
	    // 对截取的帧进行等比例缩放
	    int width = 800;
	    int height = (int) (((double) width / owidth) * oheight);
	    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
	    bi.getGraphics().drawImage(f.image.getBufferedImage().getScaledInstance(width, height, Image.SCALE_SMOOTH),
	            0, 0, null);
	    ImageIO.write(bi, "jpg", targetFile);
	    //ff.flush();
	    ff.stop();
	    return lenght;
	}*/
	
	
}
